package com.rs.game.player.dialogues;

import com.rs.game.player.QuestManager.Quests;
import com.rs.game.player.Skills;

public class CaptainLawgof extends Dialogue {

	private int npcId;

	@Override
	public void start() {
		npcId = (int) parameters[0];
		sendPlayerDialogue(Expressions.NORMAL, "Hello.");
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == -2) {
			switch (stage) {
			case -1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Guthix be praised, the cavalry has arrived! Hero, how would you like to be an honorary member of the Black Guard?");
				stage = 0;
				break;
			case 0:
				sendPlayerDialogue(Expressions.NORMAL, "The Black Guard, what's that?");
				stage = 1;
				break;
			case 1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Hawhaw! 'What's that' " + (player.getAppearence().isMale() ? "he" : "she") + " asks, what a sense of humour! The Black Guard is the finest regiment in the dwarven army. Only the best of the best are allowed to join it and then the recieve months of rigorous training.");
				stage = 2;
				break;
			case 2:
				sendNPCDialogue(npcId, Expressions.NORMAL, "However, we are currently in need of a hero, so for a limited time only I'm offering you, a human, a chance to join this prestigious regiment. What do you say?");
				stage = 3;
				break;
			case 3:
				sendOptionsDialogue("Select an Option", "I'm sorry, I'm too busy mining.", "Sure, I'd be honoured to join.");
				stage = 4;
				break;
			case 4:
				switch (componentId) {
				case OPTION_1:
					sendPlayerDialogue(Expressions.NORMAL, "I'm sorry, I'm too busy mining.");
					stage = 9; // TODO: Set Ending stage
					break;
				case OPTION_2:
					sendPlayerDialogue(Expressions.NORMAL, "Sure, I'd be honoured to join.");
					stage = 5;
					break;
				}
				break;
			case 5:
				sendNPCDialogue(npcId, Expressions.NORMAL, "That's the spirit! Now trooper, we have no time to waste - the goblins are attacking from the forests to the South.");
				stage = 6;
				break;
			case 6:
				sendNPCDialogue(npcId, Expressions.NORMAL, "There are so many of them, they are overwhelming my men and breaking through our perimeter defences; could you please try to fix the stockade by replacing the broken rails with these new ones?");
				stage = 7;
				break;
			case 7:
				sendPlayerDialogue(Expressions.NORMAL, "Sure, sounds easy enough...");
				stage = 8;
				break;
			case 8:
				if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == -2) {
					if (player.getInventory().getFreeSlots() >= 1) {
						player.getInventory().addItem(14, 6);
						player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 1);
					}
				}
				sendNPCDialogue(npcId, Expressions.NORMAL, "Report back to me once you've fixed the railings.");
				stage = 9;
				break;
			case 9:
				sendPlayerDialogue(Expressions.NORMAL, "Yes Sir, Captain!");
				stage = 10;
				break;
			case 10:
				end();
				break;
			}
		}

		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 2) {
			switch (stage) {
			case -1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Well done, trooper! The goblins seem to have stopped getting in. I think you've done the job!");
				stage = 0;
				break;
			case 0:
				sendPlayerDialogue(Expressions.NORMAL, "Great, I'll be getting on then.");
				stage = 1;
				break;
			case 1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "What? I'll have you jailed for desertion!");
				stage = 2;
				break;
			case 2:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Beside, I have another commission for you. Just before the goblins over-ran us we lost contact with our watch tower to the South, that's why the goblins managed to catch us unawares.");
				stage = 3;
				break;
			case 3:
				sendNPCDialogue(npcId, Expressions.NORMAL, "I'd like you to perform a covert operation into enemy territory, to check up on the guards we have stationed there.");
				stage = 4;
				break;
			case 4:
				sendNPCDialogue(npcId, Expressions.NORMAL, "They should have reported in by now...");
				stage = 5;
				break;
			case 5:
				sendPlayerDialogue(Expressions.NORMAL, "Okay, I'll see what I can find out.");
				stage = 6;
				break;
			case 6:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Excellent! I have two men there, the dwarf-in-charge is called Gilob, find him and tell him that I'll send him a relief guard as soon as we mop up these remaining goblins.");
				stage = 7;
				break;
			case 7:
				player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 3);
				end();
				break;
			}
		}

		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 4) {
			switch (stage) {
			case -1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Have you been to the watch tower yet?");
				stage = 0;
				break;
			case 0:
				sendPlayerDialogue(Expressions.NORMAL, "I have some terrible news for you Captain, the goblins over ran the tower, your guards fought well but were overwhelmed.");
				stage = 1;
				break;
			case 1:
				sendItemDialogue(0, "You give the Dwarf Captain his subordinate's remains...");
				stage = 2;
				break;
			case 2:
				player.getInventory().deleteItem(0, 1);
				sendNPCDialogue(npcId, Expressions.NORMAL, "I can't believe it, Gilob was the finest lietenant I had! We'll give him a fitting funeral, but what of his command? His son, Lollk was with him. Did you find his body too?");
				stage = 3;
				break;
			case 3:
				sendPlayerDialogue(Expressions.NORMAL, "No, there was only one body there, I searched pretty well.");
				stage = 4;
				break;
			case 4:
				sendNPCDialogue(npcId, Expressions.NORMAL, "The goblins must have taken him. Please traveller, seek out the goblins' hideout and return the lad to us. They alwas attack from the South-east, so they must be based down there.");
				stage = 5;
				break;
			case 5:
				sendPlayerDialogue(Expressions.NORMAL, "Okay, I'll see if I can find their hideout.");
				stage = 6;
				break;
			case 6:
				player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 5);
				end();
				break;

			}
		}
		
		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 6) {
			switch (stage) {
			case -1:
				sendPlayerDialogue(Expressions.NORMAL, "Has Lollk returned yet?");
				stage = 0;
				break;
			case 0:
				sendNPCDialogue(npcId, Expressions.NORMAL, "He has, and I thank you from the bottom of my heart - without you he'd be a goblin barbecue!");
				stage = 1;
				break;
			case 1:
				sendPlayerDialogue(Expressions.NORMAL, "Always a pleasure to help.");
				stage = 2;
				break;
			case 2:
				sendNPCDialogue(npcId, Expressions.NORMAL, "In that case could I ask one more favour of you...");
				stage = 3;
				break;
			case 3:
				sendNPCDialogue(npcId, Expressions.NORMAL, "When the goblins attacked us some of them managed to slip past my guards and sabotage our cannon. I don't have anybody who understands how it works, could you have a look at it and see if you could get it working for us, please?");
				stage = 4;
				break;
			case 4:
				sendOptionsDialogue("Select an Option", "Okay, I'll see what I can do.", "Sorry, I've done enough for today.");
				stage = 5;
				break;
			case 5:
				switch (componentId) {
				case OPTION_1:
					sendPlayerDialogue(Expressions.NORMAL, "Okay, I'll see what I can do.");
					stage = 6;
					break;
				case OPTION_2:
					sendPlayerDialogue(Expressions.NORMAL, "Sorry, I've done enough for today.");
					stage = 9;
					break;
				}
				break;
			case 6:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Thank you, take this toolkit, you'll need it...");
				stage = 7;
				break;
			case 7:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Report back to me if you manage to fix it.");
				stage = 8;
				break;
			case 8:
				player.getInventory().addItem(1, 1);
				player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 7);
				end();
				break;
			case 9:
				end();
				break;
			}
		}
		
		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 8) {
			switch (stage) {
			case -1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Well I don't believe it, it seems to be working perfectly! I seem to have underestimated you, trooper!");
				stage = 0;
				break;
			case 0:
				sendPlayerDialogue(Expressions.NORMAL, "Not bad for an adventurer eh?");
				stage = 1;
				break;
			case 1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Not bad at all, your effort is appreciated, my friend. Now, if I could figure what the thing uses as ammo...");
				stage = 2;
				break;
			case 2:
				sendNPCDialogue(npcId, Expressions.NORMAL, "The Black Guard forgot to send instructions. I know I said that was the last favor, but...");
				stage = 3;
				break;
			case 3:
				sendPlayerDialogue(Expressions.NORMAL, "What now?");
				stage = 4;
				break;
			case 4:
				sendNPCDialogue(npcId, Expressions.NORMAL, "I can't leave this post, could you go to the Black Guard base and find out what this thing actually shoots?");
				stage = 5;
				break;
			case 5:
				sendOptionsDialogue("Select an Option", "Sorry, I've really done enough.", "Okay then, just for you!");
				stage = 6;
				break;
			case 6:
				switch (componentId) {
				case OPTION_1:
					sendPlayerDialogue(Expressions.NORMAL, "Sorry, I've really done enough.");
					stage = 11;
					break;
				case OPTION_2:
					sendPlayerDialogue(Expressions.NORMAL, "Okay then, just for you!");
					stage = 7;
					break;
				}
				break;
			case 7:
				sendNPCDialogue(npcId, Expressions.NORMAL, "That's great, we were lucky you came along when you did. The base is located just South of the Ice Mountain.");
				stage = 8;
				break;
			case 8:
				sendNPCDialogue(npcId, Expressions.NORMAL, "You'll need to speak to Nulodian, the Dwarf Cannon engineer. He's the Weapons Development Chief for the Black Guard, so if anyone knows how to fire this thing, it'll be him.");
				stage = 9;
				break;
			case 9:
				sendPlayerDialogue(Expressions.NORMAL, "Okay, I'll see what I can do.");
				stage = 10;
				break;
			case 10:
				player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 9);
				end();
				break;
			case 11:
				end();
				break;
				
			}
		}
		
		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 10) {
			switch (stage) {
			case -1:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Hello trooper, any word from the Cannon Engineer?");
				stage = 0;
				break;
			case 0:
				sendPlayerDialogue(Expressions.NORMAL, "Yes, I have spoken to him.");
				stage = 1;
				break;
			case 1:
				sendPlayerDialogue(Expressions.NORMAL, "He gave me an ammo mould and some notes to give to you...");
				stage = 2;
				break;
			case 2:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Aah, of course, we make the ammo! This is great, now we will be able to defend ourselves. I don't know how to thank you...");
				stage = 3;
				break;
			case 3:
				sendPlayerDialogue(Expressions.NORMAL, "You could give me a cannon...");
				stage = 4;
				break;
			case 4:
				sendNPCDialogue(npcId, Expressions.NORMAL, "Hah! You'd be lucky, those things are worth a fortune.");
				stage = 5;
				break;
			case 5:
				sendNPCDialogue(npcId, Expressions.NORMAL, "I'll tell you what though, I'll write to the Cannon Engineer requesting him to sell you one. He controls the production of the cannons.");
				stage = 6;
				break;
			case 6:
				sendNPCDialogue(npcId, Expressions.NORMAL, "He won't be able to give you one, but for the right price, I'm sure he'll sell one to you.");
				stage = 7;
				break;
			case 7:
				sendPlayerDialogue(Expressions.NORMAL, "Hmmm... souns interesting, I might take you up on that.");
				stage = 8;
				break;
			case 8:
				player.getQuestManager().completeQuest(Quests.DWARF_CANNON);
				player.setQuestPoints(player.getQuestPoints() + 1);
				player.getSkills().addXp(Skills.CRAFTING, 750);
				player.getInventory().addItem(24155, 1);
				end();
				player.getInterfaceManager().sendInterface(277);
				player.getPackets().sendItemOnIComponent(277, 5, 1, 1);
				player.getPackets().sendIComponentText(277, 4, "You have completed the Dwarf Cannon Quest!");
				player.getPackets().sendIComponentText(277, 7, "" + player.getQuestPoints());
				player.getPackets().sendIComponentText(277, 10, "1 Quest Point");
				player.getPackets().sendIComponentText(277, 11, "750 Crafting XP");
				player.getPackets().sendIComponentText(277, 12, "Permission to purchase and");
				player.getPackets().sendIComponentText(277, 13, "use the Dwarf Multicannon");
				player.getPackets().sendIComponentText(277, 14, "Two extra spins on the");
				player.getPackets().sendIComponentText(277, 15, "Squeal of Fortune");
				player.getPackets().sendIComponentText(277, 16, "");
				player.getPackets().sendIComponentText(277, 17, "");
			}
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub

	}

}